package com.leetcode.algorithm.y22.m07;

import java.util.HashMap;
import java.util.Map;

/**
 * 1. 两数之和
 * 
 * https://leetcode.cn/problems/two-sum/
 * 
 * @author jie.deng
 *
 */
public class Question0001Solution01 {

	public int[] twoSum(int[] nums, int target) {
		// K = nums[i], V = i
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < nums.length; i++) {
			Integer tmpIdx = map.get(target - nums[i]);
			if (tmpIdx != null) {
				return new int[] { tmpIdx.intValue(), i };
			}
			map.put(nums[i], i);
		}
		return new int[] { -1, -1 };
	}
}
